<link rel="stylesheet" href="<?php echo $this->basePath('js/plugins/webuploader/webuploader.css'); ?>">
<link rel="stylesheet" href="<?php echo $this->basePath('js/plugins/webuploader/style.css'); ?>">
<style>
    #filePicker div:nth-child(2){width:100%!important;height:100%!important;}
</style>
<div class="content-wrapper">
    <?php
    $form = $this->form;
    $form->prepare();

    if($form->get('goodsMarketPrice')->getValue() >= 0) $form->get('goodsMarketPrice')->setAttributes(['value' => $form->get('goodsMarketPrice')->getValue()]);
    if($form->get('goodsPrice')->getValue() > 0) $form->get('goodsPrice')->setAttributes(['value' => $form->get('goodsPrice')->getValue()]);
    $form->get('discountPrice')->setAttributes(['value' => $form->get('discountPrice')->getValue()]);
    ?>
    <?php echo $this->form()->openTag($form); ?>
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right" id="dbshop-menu-top">
            <input type="hidden" name="goodsSaveType" id="goodsSaveType" value="">
            <a href="<?php echo $this->url('goods', [], ['query' => $this->queryData]); ?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回商品列表'); ?></a>
            <?php if (isset($this->goodsInfo)) { ?>
                <button type="submit" onclick="$('#goodsSaveType').val('saveReturnEdit');" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('保存并继续编辑'); ?></button>
            <?php } ?>
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('保存商品'); ?></button>
            <?php if (isset($this->goodsInfo)) { ?>
                <a href="<?php echo $this->url('shop-goods', ['id' => $this->goodsInfo->getGoodsId()], ['query' => ['show' => 'dbshopPreview', 'time' => $this->goodsInfo->getGoodsAddTime()]]); ?>"
                   class="btn btn-sm btn-info" target="_blank"><i class="fa fa-share"></i> <?php echo $this->translate('预览'); ?></a>
            <?php } ?>
            <?php echo $this->HelpUrl('goodsAdd'); ?>
        </h1>
    </section>

    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab"><?php echo $this->translate('基本信息'); ?></a></li>
                        <li><a href="#tab_2" data-toggle="tab"><?php echo $this->translate('分类'); ?></a></li>
                        <li><a href="#tab_10" data-toggle="tab"><?php echo $this->translate('详情'); ?></a></li>
                        <li><a href="#tab_3" data-toggle="tab"><?php echo $this->translate('图片'); ?></a></li>
                        <li><a href="#tab_4" data-toggle="tab"><?php echo $this->translate('库存'); ?></a></li>
                        <li><a href="#tab_5" data-toggle="tab"><?php echo $this->translate('优惠'); ?></a></li>
                        <li><a href="#tab_6" data-toggle="tab"><?php echo $this->translate('规格'); ?></a></li>
                        <li><a href="#tab_11" data-toggle="tab"><?php echo $this->translate('批发'); ?></a></li>
                        <li><a href="#tab_7" data-toggle="tab"><?php echo $this->translate('属性'); ?></a></li>
                        <li><a href="#tab_8" data-toggle="tab"><?php echo $this->translate('标签'); ?></a></li>
                        <?php if (isset($this->extend['form'])) { ?>
                            <li><a href="#tab_14" data-toggle="tab"><?php echo $this->translate('扩展'); ?></a></li>
                        <?php } ?>
                        <li><a href="#tab_9" data-toggle="tab"><?php echo $this->translate('自定义'); ?></a></li>
                        <li><a href="#tab_13" data-toggle="tab"><?php echo $this->translate('SEO优化'); ?></a></li>
                    </ul>
                    <div class="tab-content">
                        <?php echo $this->partial('layout/messages'); ?>

                        <?php echo $this->formElementErrors($form->get('inClassId'), ['class'=>'error-message']); ?>
                        <?php echo $this->formElementErrors($form->get('classId'), ['class'=>'error-message']); ?>
                        <div class="tab-pane active" id="tab_1">
                            <div class="box-body">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品名称'); ?><span class="must_add_value">*</span></label>
                                    <div class="col-sm-8">
                                        <?php echo $this->formElement($form->get('goodsName')); ?>
                                        <?php echo $this->formElementErrors($form->get('goodsName'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品扩展名称'); ?></label>
                                    <div class="col-sm-8">
                                        <?php echo $this->formElement($form->get('goodsExtendName')); ?>
                                        <?php echo $this->formElementErrors($form->get('goodsExtendName'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品货号'); ?><span class="must_add_value">*</span></label>
                                    <div class="col-sm-3">
                                        <?php echo $this->formElement($form->get('goodsItem')); ?>
                                        <?php echo $this->formElementErrors($form->get('goodsItem'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('市场价格'); ?></label>
                                    <div class="col-sm-3">
                                        <div class="input-group">
                                            <span class="input-group-addon"><?php echo $this->currencySymbol; ?></span>
                                            <?php echo $this->formElement($form->get('goodsMarketPrice')); ?>
                                        </div>
                                        <?php echo $this->formElementErrors($form->get('goodsMarketPrice'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品价格'); ?><span class="must_add_value">*</span></label>
                                    <div class="col-sm-3">
                                        <div class="input-group">
                                            <span class="input-group-addon"><?php echo $this->currencySymbol; ?></span>
                                            <?php echo $this->formElement($form->get('goodsPrice')); ?>
                                        </div>
                                        <?php echo $this->formElementErrors($form->get('goodsPrice'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品会员价格'); ?><p class="text-sm text-blue" style="font-weight: normal;"><?php echo $this->translate('价格大于0 生效'); ?></p></label>
                                    <div class="col-sm-3">
                                        <table class="table shop-table table-bordered" style="margin-bottom:0px;">
                                            <tbody>
                                            <?php
                                            if(isset($this->goodsInfo)) $goodsUserGroupPriceArray = unserialize($this->goodsInfo->getGoodsUserGroupPrice());
                                            foreach ($this->userGroup as $ugValue) { ?>
                                                <tr>
                                                    <td width="35%" style="padding: 0px;">&nbsp;<?php echo $this->escapeHtml($ugValue->getUserGroupName()); ?></td>
                                                    <td style="padding: 0px;">
                                                        <div class="input-group">
                                                            <span class="input-group-addon"><?php echo $this->currencySymbol; ?></span>
                                                            <input type="text" min="0" name="goodsUserGroupPrice[<?php echo $ugValue->getUserGroupId(); ?>]" class="form-control" value="<?php echo isset($goodsUserGroupPriceArray[$ugValue->getUserGroupId()]) ? $goodsUserGroupPriceArray[$ugValue->getUserGroupId()] : 0; ?>">
                                                        </div>
                                                    </td>
                                                </tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('虚拟销量'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('virtualSales')); ?>
                                        <?php echo $this->formElementErrors($form->get('virtualSales'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品品牌'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('brandId')); ?>
                                        <?php echo $this->formElementErrors($form->get('brandId'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品类型'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('goodsType')); ?>
                                        <?php echo $this->formElementErrors($form->get('goodsType'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('重量'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('goodsWeight')); ?>
                                        <?php echo $this->formElementErrors($form->get('goodsWeight'), ['class'=>'error-message']); ?>
                                    </div>
                                    <div class="col-sm-1" style="padding-left: 1px;padding-right: 0px;">
                                        <?php echo $this->formElement($form->get('goodsWeightConversion')); ?>
                                        <?php echo $this->formElementErrors($form->get('goodsWeightConversion'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品状态'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('goodsState')); ?>
                                        <?php echo $this->formElementErrors($form->get('goodsState'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('积分购买'); ?></label>
                                    <div class="col-sm-6">
                                        <label class="checkbox-inline">
                                            <?php echo $this->formElement($form->get('goodsIntegralBuy')); ?> <?php echo $this->translate('启用'); ?>
                                        </label>
                                        <p class="form-control-static text-sm"><a href="<?php echo $this->url('user-integral', ['action' => 'editIntegralType', 'id' => 1]); ?>" target="_blank"><?php echo $this->translate('点击设置积分与货币换算比'); ?></a></p>
                                        <?php echo $this->formElementErrors($form->get('goodsIntegralBuy'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_2">
                            <div class="box-body">
                                <div class="box-body table-responsive no-padding">
                                    <table class="table table-hover">
                                      <thead>
                                        <tr>
                                            <th><?php echo $this->translate('分类名称'); ?></th>
                                            <th width="20%"><?php echo $this->translate('主分类'); ?> [<span class="text-red"><?php echo $this->translate('必选'); ?></span>]</th>
                                        </tr>
                                      </thead>
                                      <tbody>
                                      <?php if($this->classList) foreach ($this->classList as $classValue) { ?>
                                        <tr>
                                            <td>
                                                <label class="checkbox-inline col-sm-12">
                                                    <?php if($classValue->getClassTopId() > 0) echo str_repeat('&nbsp;', substr_count($classValue->getClassPath(), ',') * 3); ?>
                                                    <input onclick="selectClassId('<?php echo $classValue->getClassPath(); ?>', <?php echo $classValue->getClassId(); ?>);" name="inClassId[]" <?php if(isset($this->selectedClass) && !empty($this->selectedClass) && in_array($classValue->getClassId(), $this->selectedClass)) echo 'checked'; ?> id="classId<?php echo $classValue->getClassId(); ?>" value="<?php echo $classValue->getClassId(); ?>" type="checkbox" class="minimal">
                                                    <?php echo $this->escapeHtml($classValue->getClassName() . ' (ID：' . $classValue->getClassId() . ')'); ?>
                                                    <?php if($classValue->getClassState() == 0) echo '[<strong class="text-red">'.$this->translate('禁用').'</strong>]'; ?>
                                                </label>
                                            </td>
                                            <td>
                                                <input name="classId" type="radio" <?php if(isset($this->goodsInfo) && $this->goodsInfo->getClassId() == $classValue->getClassId()) echo 'checked'; ?> value="<?php echo $classValue->getClassId(); ?>" class="minimal" style="border: 1px solid #0073b7">
                                            </td>
                                        </tr>
                                      <?php } ?>
                                      </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_10">
                            <div class="box-body">
                                <div class="col-sm-12">
                                    <script id="goodsBody" name="goodsBody" type="text/plain"><?php echo isset($this->goodsInfo) ? $this->goodsInfo->getGoodsBody() : $form->get('goodsBody')->getValue(); ?></script>
                                    <?php echo $this->formElementErrors($form->get('goodsBody'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_3">
                            <div class="box-body">
                                <button type="button" onclick="getEditNewImage();" class="btn btn-success btn-sm col-md-offset-10"><i class="fa fa-download" aria-hidden="true"></i> <?php echo $this->translate('点击获取编辑器新上传的图片'); ?></button>
                                <div id="wrapper">
                                    <div id="container">

                                        <div id="uploader">
                                            <div class="queueList">
                                                <div id="dndArea" class="placeholder">
                                                    <div id="filePicker"></div>
                                                    <p><?php echo $this->translate('或将照片拖到这里，单次最多可选300张'); ?></p>
                                                </div>
                                            </div>
                                            <div class="statusBar" style="display:none;">
                                                <div class="progress">
                                                    <span class="text">0%</span>
                                                    <span class="percentage"></span>
                                                </div><div class="info"></div>
                                                <div class="btns">
                                                    <div id="filePicker2"></div><div class="uploadBtn"><?php echo $this->translate('开始上传'); ?></div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="box-body table-responsive no-padding">
                                    <table class="table shop-table table-hover">
                                        <thead>
                                        <tr>
                                            <th width="30%"><?php echo $this->translate('图片'); ?></th>
                                            <th width="20%"><?php echo $this->translate('封面'); ?></th>
                                            <th width="20%"><?php echo $this->translate('切换'); ?></th>
                                            <th width="10%"><?php echo $this->translate('排序'); ?></th>
                                            <th width="20%"><?php echo $this->translate('操作'); ?></th>
                                        </tr>
                                        </thead>
                                        <tbody id="goodsMoreImage">
                                        <?php $goodsImageArray = []; if ($this->goodsImages) foreach ($this->goodsImages as $imageValue) {
                                            $goodsImageFile = $this->goodsHelper()->goodsImage($imageValue->getGoodsThumbnailImage());
                                            $goodsImageArray[$imageValue->getGoodsImageId()] = $goodsImageFile;
                                            ?>
                                            <tr id="trImage<?php echo $imageValue->getGoodsImageId(); ?>">
                                                <td>
                                                    <input type="hidden" name="goodsImageId[]" value="<?php echo $imageValue->getGoodsImageId(); ?>">
                                                    <img src="<?php echo $goodsImageFile; ?>" class="img-thumbnail" style="width: 60px;height: 60px;">
                                                </td>
                                                <td>
                                                    <input type="radio" name="defaultImage" <?php if(isset($this->goodsInfo) && $this->goodsInfo->getGoodsImageId() == $imageValue->getGoodsImageId()) echo 'checked'; ?> value="<?php echo $imageValue->getGoodsImageId(); ?>">
                                                </td>
                                                <td>
                                                    <input type="checkbox" name="imageSlide<?php echo $imageValue->getGoodsImageId(); ?>" id="imageSlide<?php echo $imageValue->getGoodsImageId(); ?>" value="1" <?php if ($imageValue->getImageSlide() == 1) echo 'checked="checked"'; ?>>
                                                </td>
                                                <td>
                                                    <input type="number" min="1" name="imageSort<?php echo $imageValue->getGoodsImageId(); ?>" id="imageSort<?php echo $imageValue->getGoodsImageId(); ?>" value="<?php echo $imageValue->getImageSort(); ?>" class="form-control input-sm">
                                                </td>
                                                <td>
                                                    <button type="button" class="btn btn-xs btn-success" onclick="updateGoodsImage(<?php echo $imageValue->getGoodsImageId(); ?>);"><i class="fa fa-refresh"></i> <?php echo $this->translate('更新'); ?></button><button type="button" class="btn btn-xs btn-danger" onclick="deleteGoodsImage(<?php echo $imageValue->getGoodsImageId(); ?>);" style="margin-left: 10px;"><i class="fa fa-trash"></i> <?php echo $this->translate('删除'); ?></button>
                                                </td>
                                            </tr>
                                        <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_4">
                            <div class="box-body">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('库存数量'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('stockNum')); ?>
                                        <?php echo $this->formElementErrors($form->get('stockNum'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('前台库存显示'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('stockShow')); ?>
                                        <?php echo $this->formElementErrors($form->get('stockShow'), ['class'=>'error-message']); ?>
                                    </div>
                                    <div class="col-sm-3">
                                        <?php echo $this->formElement($form->get('stockShowState')); ?>
                                        <?php echo $this->formElementErrors($form->get('stockShowState'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品缺货时数量'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('stockOutSetNum')); ?>
                                        <?php echo $this->formElementErrors($form->get('stockOutSetNum'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('缺货显示'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('stockOutShow')); ?>
                                        <?php echo $this->formElementErrors($form->get('stockOutShow'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('购物车购买最少数量'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('cartBuyMinNum')); ?>
                                        <?php echo $this->formElementErrors($form->get('cartBuyMinNum'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('购物车购买最多数量'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('cartBuyMaxNum')); ?>
                                        <?php echo $this->formElementErrors($form->get('cartBuyMaxNum'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('每人最多购买次数'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('personBuyMax')); ?>
                                        <?php echo $this->formElementErrors($form->get('personBuyMax'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_5">
                            <div class="box-body">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('优惠价格'); ?></label>
                                    <div class="col-sm-3">
                                        <div class="input-group">
                                            <span class="input-group-addon"><?php echo $this->currencySymbol; ?></span><?php echo $this->formElement($form->get('discountPrice')); ?>
                                        </div>
                                        <?php echo $this->formElementErrors($form->get('discountPrice'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('开始时间'); ?></label>
                                    <div class="col-sm-3">
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <?php echo $this->formElement($form->get('discountStartTime')); ?>
                                        </div>
                                        <?php echo $this->formElementErrors($form->get('discountStartTime'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('结束时间'); ?></label>
                                    <div class="col-sm-3">
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <?php echo $this->formElement($form->get('discountEndTime')); ?>
                                        </div>
                                        <?php echo $this->formElementErrors($form->get('discountEndTime'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('客户组范围'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('discountUserGroupType')); ?>
                                        <?php echo $this->formElementErrors($form->get('discountUserGroupType'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group<?php if($form->get('discountUserGroupType')->getValue() == 'allUser' || $form->get('discountUserGroupType')->getValue() == '') echo ' hidden' ?>" id="divDiscountUserGroup">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('选择客户组'); ?></label>
                                    <div class="col-sm-10">
                                        <?php echo $this->formElement($form->get('discountUserGroup')); ?>
                                        <?php echo $this->formElementErrors($form->get('discountUserGroup'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_8">
                            <div class="box-body">
                                <?php $specGroup = []; if($this->goodsTagGroup) foreach ($this->goodsTagGroup as $tagGroupValue) { if($tagGroupValue->getIsGoodsSpec() == 1) $specGroup[] = $tagGroupValue; ?>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"><?php echo $this->escapeHtml($tagGroupValue->getTagGroupName()); if(!empty($tagGroupValue->getTagGroupMark())) echo '['.$this->escapeHtml($tagGroupValue->getTagGroupMark()).']'; ?></label>
                                        <div class="col-sm-10">
                                            <?php if(isset($this->goodsTag[$tagGroupValue->getTagGroupId()])) foreach ($this->goodsTag[$tagGroupValue->getTagGroupId()] as $tagValue) { ?>
                                                <label class="checkbox-inline"><input type="checkbox" <?php if(isset($tagValue['inTagId']) && $tagValue['inTagId'] > 0) echo 'checked'; ?> value="<?php echo $tagValue['tagId']; ?>" name="tagId[]"><?php echo $this->escapeHtml($tagValue['tagName']); ?></label>
                                            <?php } ?>
                                        </div>
                                    </div>
                                <?php } ?>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_6">
                            <div class="box-body">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('选择规格组'); ?></label>
                                    <div class="col-sm-10">
                                        <?php if(!empty($specGroup)) foreach ($specGroup as $specGroupValue) { ?>
                                            <label class="checkbox-inline"><input type="checkbox" <?php if(isset($this->specGroupTagArray[$specGroupValue->getTagGroupId()])) echo 'checked'; ?> value="<?php echo $specGroupValue->getTagGroupId(); ?>" name="goodsSpecGroupId[]" id="goodsSpecGroupId<?php echo $specGroupValue->getTagGroupId(); ?>" onclick="selectGoodsSpecGroupId(<?php echo $specGroupValue->getTagGroupId(); ?>);" title="<?php echo $this->escapeHtml($specGroupValue->getTagGroupName()); ?>"><?php echo $this->escapeHtml($specGroupValue->getTagGroupName()); ?><?php if ($specGroupValue->getTagGroupMark()) echo '['.$this->escapeHtml($specGroupValue->getTagGroupMark()).']'; ?></label>
                                        <?php } else { ?>
                                            <a href="https://bbs.dbshop.net/forum.php?mod=viewthread&tid=2442" target="_blank" class="btn btn-info"><i class="fa fa-question-circle-o" aria-hidden="true"></i> <?php echo $this->translate('暂无规格组，点击查看商品规格设置教程'); ?></a>
                                        <?php } ?>
                                    </div>
                                </div>
                                <hr>
                                <div id="specGroupValueShow">
                                    <?php $rowSpanNum = 1; if(!empty($this->specGroupTagArray)) foreach ($this->specGroupTagArray as $gtKey => $gtValue) {
                                        if($gtValue['groupImage'] != 1 && !empty($gtValue['selectedTagId'])) $rowSpanNum *= count($gtValue['selectedTagId']);
                                        ?>
                                        <div class="form-group" id="specGroupValueDiv<?php echo $gtKey; ?>">
                                            <label class="col-sm-2 control-label"><?php echo $gtValue['tagGroupName'];  ?> - <?php echo $this->translate('图'); ?> <input type="checkbox" <?php if($gtValue['groupImage'] == 1) { $selectedSpecGroupImage = 1; echo 'checked';} ?> class="checkbox-inline" name="specImage[]" id="specImage<?php echo $gtKey; ?>" onclick="selectSpecImage(<?php echo $gtKey; ?>);" value="<?php echo $gtKey; ?>"></label>
                                            <div class="col-sm-10">
                                                <?php foreach ($this->goodsTag[$gtKey] as $tTagValue) { $tagNameArray[$tTagValue['tagId']] = $this->escapeHtml($tTagValue['tagName']); ?>
                                                    <label class="checkbox-inline"><input type="checkbox" <?php if(!empty($gtValue['selectedTagId']) && in_array($tTagValue['tagId'], $gtValue['selectedTagId'])) echo 'checked'; ?> value="<?php echo $tTagValue['tagId']; ?>" name="goodsSpecGroup<?php echo $gtKey; ?>[]" id="goodsSpecGroup<?php echo $gtKey.'_'.$tTagValue['tagId']; ?>" title="<?php echo $this->escapeHtml($tTagValue['tagName']); ?>"><?php echo $this->escapeHtml($tTagValue['tagName']); ?></label>
                                                <?php } ?>
                                            </div>
                                        </div>
                                    <?php } ?>
                                </div>
                                <div class="col-md-offset-2">
                                    <button type="button" id="onclickClearSpecGoods" class="btn btn-warning btn-sm"><i class="fa fa-repeat"></i> <?php echo $this->translate('清空规格'); ?></button>&nbsp;&nbsp;
                                    <button type="button" id="onclickCreateSpecGoods" class="btn btn-success btn-sm"><i class="fa fa-plus-circle fa-lg"></i> <?php echo $this->translate('点击生成规格商品'); ?></button>
                                    <small class="text-blue"><?php echo $this->translate('若选择了规格组具体规格信息，必须点击按钮，生成规格商品。'); ?></small>
                                </div>
                                <div class="box-body table-responsive no-padding" style="margin-top: 15px;">
                                    <table class="table shop-table table-bordered">
                                        <thead>
                                        <tr class="shop-bg-thead">
                                            <th width="20%"><?php echo $this->translate('规格'); ?></th>
                                            <th width="12%"><?php echo $this->translate('价格'); ?><span class="must_add_value">*</span><button type="button" onclick="editSpecGoodsPrice();" class="btn btn-primary btn-xs"><i class="fa fa-list"></i> <?php echo $this->translate('批改'); ?></button></th>
                                            <th width="10%"><?php echo $this->translate('库存'); ?><span class="must_add_value">*</span><button type="button" onclick="editSpecGoodsStock();" class="btn btn-primary btn-xs"><i class="fa fa-list"></i> <?php echo $this->translate('批改'); ?></button></th>
                                            <th width="10%"><?php echo $this->translate('货号'); ?>&nbsp;<button type="button" onclick="editSpecGoodsItem();" class="btn btn-primary btn-xs"><i class="fa fa-list"></i> <?php echo $this->translate('批改'); ?></button></th>
                                            <th width="10%"><?php echo $this->translate('重量'); ?>&nbsp;<button type="button" onclick="editSpecGoodsWeight();" class="btn btn-primary btn-xs"><i class="fa fa-list"></i> <?php echo $this->translate('批改'); ?></button></th>
                                            <th width="18%"><?php echo $this->translate('会员价'); ?></th>
                                            <th width="15%"><?php echo $this->translate('图片'); ?></th>
                                        </tr>
                                        </thead>
                                        <tbody id="tbodySpecGoodsHtml">
                                            <?php if($this->inSpecGoods) foreach ($this->inSpecGoods as $sgKey => $sgValue) {
                                                    $specTagStr = '';
                                                    $specTagIdArray = explode('-', $sgValue->getSpecTagId());
                                                    foreach ($specTagIdArray as $sTagId) {
                                                        if (isset($tagNameArray[$sTagId])) $specTagStr .= $tagNameArray[$sTagId] . '|';
                                                    }
                                                ?>
                                                <tr id="spec-tr-<?php echo $sgValue->getSpecTagId(); ?>">
                                                    <td><input type="hidden" name="specTagIdStr[]" value="<?php echo $sgValue->getSpecTagId(); ?>"><?php echo rtrim($specTagStr, '|'); ?></td>
                                                    <td>
                                                        <div class="input-group">
                                                            <span class="input-group-addon"><?php echo $this->currencySymbol; ?></span>
                                                            <input type="text" name="specGoodsPrice[]" id="specGoodsPrice<?php echo $sgValue->getSpecTagId(); ?>" value="<?php echo $sgValue->getSpecGoodsPrice(); ?>" class="form-control input-sm">
                                                        </div>
                                                    </td>
                                                    <td><input type="number" min="0" name="specGoodsStock[]" id="specGoodsStock<?php echo $sgValue->getSpecTagId(); ?>" value="<?php echo $sgValue->getSpecGoodsStock(); ?>" class="form-control input-sm"></td>
                                                    <td><input type="text" name="specGoodsItem[]" id="specGoodsItem<?php echo $sgValue->getSpecTagId(); ?>" value="<?php echo $sgValue->getSpecGoodsItem(); ?>" class="form-control input-sm specGoodsItem"></td>
                                                    <td><input type="number" min="0" name="specGoodsWeight[]" id="specGoodsWeight<?php echo $sgValue->getSpecTagId(); ?>" value="<?php echo $sgValue->getSpecGoodsWeight(); ?>" class="form-control input-sm"></td>
                                                    <td>
                                                        <table class="table shop-table table-bordered" style="margin-bottom:0px;">
                                                            <tbody>
                                                            <?php $specGoodsUserGroupPriceArray = unserialize($sgValue->getSpecGoodsUserGroupPrice()); foreach ($this->userGroup as $ugValue) { ?>
                                                            <tr>
                                                                <td width="35%" style="padding: 0px;">&nbsp;<?php echo $this->escapeHtml($ugValue->getUserGroupName()); ?></td>
                                                                <td style="padding: 0px;">
                                                                    <div class="input-group">
                                                                        <span class="input-group-addon"><?php echo $this->currencySymbol; ?></span>
                                                                        <input type="text" name="specGoodsUserGroupPrice[<?php echo $sgValue->getSpecTagId(); ?>][<?php echo $ugValue->getUserGroupId(); ?>]" id="specGoodsUserGroupPrice-<?php echo $sgValue->getSpecTagId(); ?>-<?php echo $ugValue->getUserGroupId(); ?>" class="form-control input-sm" value="<?php echo isset($specGoodsUserGroupPriceArray[$ugValue->getUserGroupId()]) ? $specGoodsUserGroupPriceArray[$ugValue->getUserGroupId()] : 0; ?>">
                                                                    </div>
                                                                </td>
                                                            </tr>
                                                            <?php } ?>
                                                            </tbody>
                                                        </table>
                                                    </td>
                                                    <?php
                                                    if(isset($selectedSpecGroupImage)) {
                                                        if($rowSpanNum >= 1 && $sgKey%$rowSpanNum == 0) { $specGoodsImageStr = '';
                                                        ?>
                                                        <td <?php if($rowSpanNum > 1) echo 'rowspan="'.$rowSpanNum.'"'; ?>>
                                                            <p id="insert-spec-image-<?php echo $specTagIdArray[0]; ?>">
                                                                <?php if(!empty($this->inSpecGoodsImage)) foreach ($this->inSpecGoodsImage as $inSpecImage) { if($inSpecImage->getTagId() == $specTagIdArray[0]) { $specGoodsImageStr .= $inSpecImage->getGoodsImageId() . ','; ?>
                                                                    <img src="<?php echo $goodsImageArray[$inSpecImage->getGoodsImageId()]; ?>" style="height: 50px;margin-left: 5px;margin-bottom: 5px;border: 1px solid #ddd;padding: 2px;">
                                                                <?php } } ?>
                                                            </p>
                                                            <button type="button" onclick="selectGoodsSpecImage(<?php echo $specTagIdArray[0]; ?>);" class="btn bg-olive btn-flat" style="margin-left: 5px;"><i class="fa fa-pencil-square-o"></i></button><input type="hidden" name="specGoodsImageStr[<?php echo $specTagIdArray[0]; ?>]" id="specGoodsImageStr<?php echo $specTagIdArray[0]; ?>" value="<?php echo rtrim($specGoodsImageStr, ','); ?>">
                                                        </td>
                                                    <?php } } else { ?>
                                                        <td><?php echo $this->translate('无'); ?></td>
                                                    <?php } ?>
                                                </tr>
                                            <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_11">
                            <div class="box-body">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品批发状态'); ?></label>
                                    <div class="col-sm-2">
                                        <label class="checkbox-inline">
                                            <?php echo $this->formElement($form->get('wholesaleState')); ?> <?php echo $this->translate('启用'); ?>
                                            <?php echo $this->formElementErrors($form->get('wholesaleState'), ['class'=>'error-message']); ?>
                                        </label>
                                    </div>
                                </div>
                                <hr>
                                <?php for($i=1; $i<=10; $i++) { ?>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"><?php echo $this->translate('批发购买数量区间') . '-'.$i; ?></label>
                                        <div class="col-sm-3">
                                            <div class="input-group">
                                                <span class="input-group-addon"><?php echo $this->translate('大于等于[>=]'); ?></span>
                                                <input type="number" min="0" name="wholesaleStartNum[<?php echo $i; ?>]" class="form-control" value="<?php if(isset($this->inGoodsWholesale[$i]['wholesaleStartNum']) && !empty($this->inGoodsWholesale[$i]['wholesaleStartNum'])) echo $this->inGoodsWholesale[$i]['wholesaleStartNum']; ?>">
                                            </div>
                                        </div>
                                        <div class="col-sm-3">
                                            <div class="input-group">
                                                <span class="input-group-addon"><?php echo $this->translate('小于等于[<=]'); ?></span>
                                                <input type="number" min="0" name="wholesaleEndNum[<?php echo $i; ?>]" class="form-control" value="<?php if(isset($this->inGoodsWholesale[$i]['wholesaleEndNum']) && !empty($this->inGoodsWholesale[$i]['wholesaleEndNum'])) echo $this->inGoodsWholesale[$i]['wholesaleEndNum']; ?>">
                                            </div>
                                        </div>
                                        <div class="col-sm-2">
                                            <div class="input-group">
                                                <span class="input-group-addon"><?php echo $this->translate('单价') . $this->currencySymbol; ?></span>
                                                <input type="text" name="wholesalePrice[<?php echo $i; ?>]" class="form-control" value="<?php if(isset($this->inGoodsWholesale[$i]['wholesalePrice']) && !empty($this->inGoodsWholesale[$i]['wholesalePrice'])) echo $this->inGoodsWholesale[$i]['wholesalePrice']; ?>">
                                            </div>
                                        </div>
                                    </div>
                                <?php } ?>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_7">
                            <div class="box-body">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品属性分组'); ?></label>
                                    <div class="col-sm-4">
                                        <?php echo $this->formElement($form->get('attributeGroupId')); ?>
                                        <?php echo $this->formElementErrors($form->get('attributeGroupId'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div id="attributeShow">
                                    <?php if(isset($this->goodsAttributeHtml)) echo $this->goodsAttributeHtml; ?>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_9">
                            <div class="box-body">
                                <?php for($i=1; $i<=10; $i++) { ?>
                                    <div class="form-group">
                                        <div class="col-sm-2">
                                            <input name="customTitle[<?php echo $i; ?>]" value="<?php if(isset($this->inGoodsCustom[$i]['customTitle']) && !empty($this->inGoodsCustom[$i]['customTitle'])) echo $this->escapeHtml($this->inGoodsCustom[$i]['customTitle']); ?>" class="form-control">
                                        </div>
                                        <div class="col-sm-8">
                                            <input type="text" name="customContent[<?php echo $i; ?>]" class="form-control" value="<?php if(isset($this->inGoodsCustom[$i]['customContent']) && !empty($this->inGoodsCustom[$i]['customContent'])) echo $this->escapeHtml($this->inGoodsCustom[$i]['customContent']); ?>">
                                        </div>
                                        <div class="checkbox-inline"><input type="checkbox" name="frontShow[<?php echo $i; ?>]" value="1" <?php if(isset($this->inGoodsCustom[$i]['frontShow']) && $this->inGoodsCustom[$i]['frontShow'] == 1) echo 'checked'; ?>> <?php echo $this->translate('前台显示'); ?></div>
                                    </div>
                                <?php } ?>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_13">
                            <div class="box-body">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品关键字'); ?></label>
                                    <div class="col-sm-8">
                                        <?php echo $this->formElement($form->get('goodsKeywords')); ?>
                                        <?php echo $this->formElementErrors($form->get('goodsKeywords'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('商品描述'); ?></label>
                                    <div class="col-sm-8">
                                        <?php echo $this->formElement($form->get('goodsDescription')); ?>
                                        <?php echo $this->formElementErrors($form->get('goodsDescription'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php if (isset($this->extend['form']) && isset($this->extend['formExtend'])) { ?>
                            <div class="tab-pane" id="tab_14">
                                <div class="box-body">
                                    <?php echo $this->adminHelper()->showExtendForm($this->extend); ?>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </div>
            </div>

    </section>
    <?php echo $this->form()->closeTag(); ?>
</div>
<script type="text/javascript" src="<?php echo $this->basePath('js/plugins/webuploader/webuploader.min.js'); ?>"></script>
<script type="text/javascript">
    var dbshopUploadServer = '<?php echo isset($this->goodsInfo) ? $this->url('goods', ['action'=> 'uploadGoodsImage', 'id' => $this->goodsInfo->getGoodsId()]) : $this->url('goods', ['action'=> 'uploadGoodsImage']); ?>';
    var basePath = '<?php echo $this->basePath('/'); ?>';
</script>
<script type="text/javascript" src="<?php echo $this->basePath('js/plugins/webuploader/upload.js'); ?>"></script>

<?php echo $this->partial('common/editor',['edit_array'=>['goodsBody'],'edit_config'=>["initialFrameHeight:450", 'serverUrl:"'.$this->url('editor', ['action'=> 'uEditorUpload','type' => 'goods', 'id' => isset($this->goodsInfo) ? $this->goodsInfo->getGoodsId() : 0]).'"']]); ?>

<script type="text/javascript">
    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            rules: {
                goodsName: {
                    required: true
                },
                goodsItem: {
                    required: true
                },
                goodsPrice: {
                    required: true,
                    number: true,
                    min: 0
                }
            },
            messages: {
                goodsName: {
                    required: "<?php echo $this->translate('商品名称不能为空!'); ?>"
                },
                goodsItem: {
                    required: "<?php echo $this->translate('商品货号不能为空!'); ?>"
                },
                goodsPrice: {
                    required: "<?php echo $this->translate('商品价格不能为空!'); ?>",
                    number: "<?php echo $this->translate('商品价格必须为数字!'); ?>",
                    min: "<?php echo $this->translate('商品价格不能小于0!'); ?>"
                }
            }
        });
    });
    function goodsFormSubmit() {
        let selectInClassId = false;
        if($("input[name='inClassId[]']").length > 0) {
            $("input[name='inClassId[]']").each(function() {
                if(this.checked) selectInClassId = true;
            });
            if($('input:radio[name="classId"]').length > 0) {
                if($('input:radio[name="classId"]:checked').val() == null) selectInClassId = false;
            } else selectInClassId = false;
        }
        if(!selectInClassId) {
            shopMessage('<?php echo $this->translate('请选择商品分类及商品主分类!'); ?>');
            return false;
        }

        if($("input[name='specGoodsPrice[]']").length > 0) {
            let specGoodsStatus = true;
            $("input[name='specGoodsPrice[]']").each(function() {
                if(isNaN(this.value) || this.value <= 0) {
                    shopMessage('<?php echo $this->translate('规格商品价格要大于0!'); ?>');
                    $('#'+this.id).focus();
                    specGoodsStatus = false;
                    return false;
                }
            });
            if(!specGoodsStatus) return false;

            $("input[name='specGoodsStock[]']").each(function() {
                if(isNaN(this.value) || this.value < 0) {
                    shopMessage('<?php echo $this->translate('规格商品库存要大于或等于0!'); ?>');
                    $('#'+this.id).focus();
                    specGoodsStatus = false;
                    return false;
                }
            });
            if(!specGoodsStatus) return false;
        }

        return true;
    }

    //优惠开始时间
    laydate.render({
        elem: '#discountStartTime'
        ,type: 'datetime'
    });
    //优惠结束时间
    laydate.render({
        elem: '#discountEndTime'
        ,type: 'datetime'
    });
    //客户组范围选择
    $('#discountUserGroupType').change(function () {
        if(this.value == 'userGroup') $('#divDiscountUserGroup').removeClass('hidden');
        else $('#divDiscountUserGroup').addClass('hidden');
    });

    //获取属性组信息
    $('#attributeGroupId').change(function () {
        $.post("<?php echo $this->url('goods', ['action'=> 'ajaxGoodsAttributeGroup']);?>", {attributeGroupId:this.value, goodsId:<?php echo isset($this->goodsInfo) ? $this->goodsInfo->getGoodsId() : 0; ?>}, function (data) {
            $('#attributeShow').html(data.htmlInput);
        }, 'json');
    });

    //选择哪个规格添加图片
    function selectSpecImage(tagGroupId) {
        if($('#specImage'+tagGroupId).prop("checked")) {
            $("input[name='specImage[]']").each(function() {
                if(this.checked && this.value != tagGroupId) $('#specImage'+this.value).prop("checked", false);
            })
        }
    }

    //生成规格商品
    $('#onclickCreateSpecGoods').click(function () {
        let groupArray      = new Array();
        let tagNameObject   = [];
        let specImageId     = 0;
        let rowSpanNum      = 1;
        $("input[name='specImage[]']").each(function() {
            if(this.checked) {
                specImageId = this.value;
                let tagArray = [];
                $("input[name='goodsSpecGroup"+this.value+"[]']").each(function() {
                    if(this.checked) {
                        tagArray.push(this.value);
                        tagNameObject[this.value] = this.title;
                    }
                });
                if(tagArray.length > 0) groupArray.push(tagArray);
            }
        });

        $("input[name='goodsSpecGroupId[]']").each(function() {
            if(this.checked && this.value != specImageId) {
                let tagArray    = [];
                $("input[name='goodsSpecGroup"+this.value+"[]']").each(function() {
                    if(this.checked) {
                        tagArray.push(this.value);
                        tagNameObject[this.value] = this.title;
                    }
                });
                if(tagArray.length > 0) {
                    groupArray.push(tagArray);
                    if(specImageId > 0) rowSpanNum *= tagArray.length;
                }
            }
        });

        if(groupArray.length > 0) {
            let createSpec = [];
            if (groupArray.length <= 1) {
                for (let gi = 0; gi < groupArray[0].length; gi++) {
                    createSpec.push([groupArray[0][gi]]);
                }
            } else createSpec  = descartes(groupArray);

            let specGoodsItemStartNum = $(".specGoodsItem").length;

            let htmlStr     = '';
            let specGoodsItem = $('#goodsItem').val();
            for (let i = 0; i < createSpec.length; i++) {
                let specStr = '';
                let tagIdStr= '';
                for (let ii = 0; ii < createSpec[i].length; ii++) {
                    specStr += tagNameObject[createSpec[i][ii]] + '|';
                    tagIdStr+= createSpec[i][ii] + '-';
                }
                tagIdStr = tagIdStr.substring(0, tagIdStr.lastIndexOf('-'));

                let goodsItemStr = '';
                if ($('#specGoodsItem'+tagIdStr).length > 0) {
                    goodsItemStr = $('#specGoodsItem'+tagIdStr).val();
                } else {
                    specGoodsItemStartNum++;
                    goodsItemStr = specGoodsItem + '-' + specGoodsItemStartNum;
                }

                htmlStr += '<tr id="spec-tr-'+tagIdStr+'">';
                htmlStr += '<td><input type="hidden" name="specTagIdStr[]" value="'+tagIdStr+'">'+specStr.substring(0, specStr.lastIndexOf('|'))+'</td>';
                htmlStr += '<td><div class="input-group"><span class="input-group-addon"><?php echo $this->currencySymbol; ?></span><input type="text" name="specGoodsPrice[]" id="specGoodsPrice'+tagIdStr+'" value="'+($('#specGoodsPrice'+tagIdStr).length > 0 ? $('#specGoodsPrice'+tagIdStr).val() : '')+'" class="form-control input-sm"></div></td>';
                htmlStr += '<td><input type="number" min="0" name="specGoodsStock[]" id="specGoodsStock'+tagIdStr+'" value="'+($('#specGoodsStock'+tagIdStr).length > 0 ? $('#specGoodsStock'+tagIdStr).val() : 10)+'" class="form-control input-sm"></td>';
                htmlStr += '<td><input type="text" name="specGoodsItem[]" id="specGoodsItem'+tagIdStr+'" value="'+goodsItemStr+'" class="form-control input-sm specGoodsItem"></td>';
                htmlStr += '<td><input type="number" min="0" name="specGoodsWeight[]" id="specGoodsWeight'+tagIdStr+'" value="'+($('#specGoodsWeight'+tagIdStr).length > 0 ? $('#specGoodsWeight'+tagIdStr).val() : 0)+'" class="form-control input-sm"></td>';
                htmlStr += '<td>';
                htmlStr += '<table class="table shop-table table-bordered" style="margin-bottom:0px;">';
                <?php foreach ($this->userGroup as $ugValue) { ?>
                htmlStr += '<tr>';
                htmlStr += '<td width="35%" style="padding: 0px;">&nbsp;<?php echo $this->escapeHtml($ugValue->getUserGroupName()); ?></td>';
                htmlStr += '<td style="padding: 0px;">';
                htmlStr += '<div class="input-group">';
                htmlStr += '<span class="input-group-addon"><?php echo $this->currencySymbol; ?></span>';
                htmlStr += '<input type="text" name="specGoodsUserGroupPrice['+tagIdStr+'][<?php echo $ugValue->getUserGroupId(); ?>]" id="specGoodsUserGroupPrice-'+tagIdStr+'-<?php echo $ugValue->getUserGroupId(); ?>" class="form-control input-sm" value="'+($('#specGoodsUserGroupPrice-'+tagIdStr+'-<?php echo $ugValue->getUserGroupId(); ?>').length > 0 ? $('#specGoodsUserGroupPrice-'+tagIdStr+'-<?php echo $ugValue->getUserGroupId(); ?>').val() : 0)+'">';
                htmlStr += '</div>';
                htmlStr += '</td>';
                htmlStr += '</tr>';
                <?php } ?>
                htmlStr += '</table>';
                htmlStr += '</td>';
                if(specImageId > 0) {
                    if(rowSpanNum > 1 && i%rowSpanNum == 0) htmlStr += '<td rowspan="'+rowSpanNum+'"><p id="insert-spec-image-'+createSpec[i][0]+'">'+($('#insert-spec-image-'+createSpec[i][0]).length > 0 ? $('#insert-spec-image-'+createSpec[i][0]).html() : '')+'</p><button type="button" onclick="selectGoodsSpecImage('+createSpec[i][0]+');" class="btn bg-olive btn-flat" style="margin-left: 5px;"><i class="fa fa-pencil-square-o"></i></button><input type="hidden" name="specGoodsImageStr['+createSpec[i][0]+']" id="specGoodsImageStr'+createSpec[i][0]+'" value="'+($('#specGoodsImageStr'+createSpec[i][0]).length > 0 ? $('#specGoodsImageStr'+createSpec[i][0]).val() : '')+'"></td>';
                    else if (rowSpanNum == 1) htmlStr += '<td><p id="insert-spec-image-'+createSpec[i][0]+'">'+($('#insert-spec-image-'+createSpec[i][0]).length > 0 ? $('#insert-spec-image-'+createSpec[i][0]).html() : '')+'</p><button type="button" onclick="selectGoodsSpecImage('+createSpec[i][0]+');" class="btn bg-olive btn-flat" style="margin-left: 5px;"><i class="fa fa-pencil-square-o"></i></button><input type="hidden" name="specGoodsImageStr['+createSpec[i][0]+']" id="specGoodsImageStr'+createSpec[i][0]+'" value="'+($('#specGoodsImageStr'+createSpec[i][0]).length > 0 ? $('#specGoodsImageStr'+createSpec[i][0]).val() : '')+'"></td>';
                } else htmlStr += '<td>无</td>';
                htmlStr += '</tr>';
            }

            $('#tbodySpecGoodsHtml').html('');
            $('#tbodySpecGoodsHtml').prepend(htmlStr);
        } else {
            $('#tbodySpecGoodsHtml').html('');
        }
    });
    //清空规格商品
    $("#onclickClearSpecGoods").click(function () {
        $("input[name='goodsSpecGroupId[]']").each(function() {
            $("input[name='goodsSpecGroup"+this.value+"[]']").prop("checked", false);
        });
        $("input[name='specImage[]']").prop("checked", false);
        $('#tbodySpecGoodsHtml').html('');
    });

    /**
     * 更新商品图片
     * @param goodsImageId
     */
    function updateGoodsImage(goodsImageId) {
        $.post("<?php echo $this->url('goods', ['action'=> 'ajaxUpdateGoodsImage']);?>", {goodsImageId:goodsImageId, imageSlide:$("#imageSlide"+goodsImageId).is(':checked'), imageSort:$('#imageSort'+goodsImageId).val()}, function (data) {
            shopMessage(data.message);
        }, 'json');
    }

    /**
     * 删除商品图片
     * @param goodsImageId
     */
    function deleteGoodsImage(goodsImageId) {
        $.post("<?php echo $this->url('goods', ['action'=> 'ajaxDeleteGoodsImage']);?>", {goodsImageId:goodsImageId}, function (data) {
            if(data.state == 'success') $('#trImage'+goodsImageId).remove();
            else shopMessage(data.message);
        }, 'json');
    }

    /**
     * 获取规格(标签)组的内容
     * @param goodsSpecGroupId
     */
    function selectGoodsSpecGroupId(goodsSpecGroupId) {
        if($('#goodsSpecGroupId'+goodsSpecGroupId).prop("checked")) {
            $.post("<?php echo $this->url('goods', ['action'=> 'ajaxGoodsSpecGroup']);?>", {goodsSpecGroupId:goodsSpecGroupId}, function (data) {
                if(data.state == 'success') $('#specGroupValueShow').append(data.html);
                else {
                    shopMessage(data.message);
                    $('#goodsSpecGroupId'+goodsSpecGroupId).prop("checked", false);
                }
            }, 'json');
        } else {
            $('#specGroupValueDiv'+goodsSpecGroupId).remove();
        }
    }

    //规格选择图片
    function selectGoodsSpecImage(tagId) {
        $.post('<?php echo isset($this->goodsInfo) ? $this->url('goods', ['action'=> 'ajaxSpecGoodsImage', 'id' => $this->goodsInfo->getGoodsId()]) : $this->url('goods', ['action'=> 'ajaxSpecGoodsImage']);?>', {tagId: tagId, specGoodsImageStr: $("#specGoodsImageStr"+tagId).val()}, function(data){
            if(data.state == 'true') {
                layer.open({
                    title: data.tagTitle + " - <?php echo $this->translate('选择规格图片'); ?> <small>[<?php echo sprintf($this->translate('商品图片为 %s切换%s 类型，在此显示'), '<b>', '</b>'); ?>]</small>",
                    type: 1,
                    skin: 'layui-layer-rim',
                    area: ['800px', '600px'], //宽高
                    content: data.imageHtml,
                    btn: '选择完毕',
                    yes: function(index, layero){
                        let imageIdStr = '';
                        $('#insert-spec-image-'+tagId).html('');
                        $(".image-list").each(function() {
                            if($('#'+this.id).data('title') == 1) {
                                imageIdStr += $('#'+this.id).data('id')+',';
                                $('#insert-spec-image-'+tagId).prepend('<img src="'+this.src+'" style="height: 50px;margin-left: 5px;margin-bottom: 5px;border: 1px solid #ddd;padding: 2px;">');
                            }
                        });
                        $("#specGoodsImageStr"+tagId).val(imageIdStr.substring(0, imageIdStr.lastIndexOf(',')));

                        layer.close(index);
                    }

                });
            } else shopMessage(data.message);
        });
    }
    function clickSpecImage(imageId) {
        let selectState = $('#sGoodsImage'+imageId).data('title');
        if(selectState == 1) {
            $('#sGoodsImage'+imageId).removeClass('image-selected-border');
            $('#sGoodsImage'+imageId).data('title', 0);
        } else {
            $('#sGoodsImage'+imageId).addClass('image-selected-border');
            $('#sGoodsImage'+imageId).data('title', 1);
        }
    }

    //批量修改规格商品价格
    function editSpecGoodsPrice() {
        let editHtml = '<div class="box-body">';
        editHtml += '<div class="col-sm-4" style="padding-right: 2px;"><select id="edit-spec-goods-price-type" class="form-control input-sm"><option value="1">[<?php echo $this->translate('增加'); ?>]+</option><option value="2">[<?php echo $this->translate('减少'); ?>]-</option></select></div>';
        editHtml += '<div class="col-sm-5" style="padding-left: 2px;"><div class="input-group"><span class="input-group-addon"><?php echo $this->currencySymbol; ?></span><input type="number" min="0" id="edit-spec-goods-price" value="0" class="form-control input-sm"></div></div>';
        editHtml += '</div>';
        layer.open({
            title: "<?php echo $this->translate('批量修改规格商品价格'); ?>",
            type: 1,
            skin: 'layui-layer-rim',
            area: ['400px', '180px'], //宽高
            content: editHtml,
            btn: '<?php echo $this->translate('点击修改'); ?>',
            yes: function(index){
                let editGoodsPrice = $('#edit-spec-goods-price').val();
                let editGoodsPriceType = $('#edit-spec-goods-price-type').val();
                let goodsPrice = 0;
                if(editGoodsPrice > 0) {
                    $("input[name='specGoodsPrice[]']").each(function() {
                        goodsPrice = editGoodsPriceType == 1 ? accAdd(this.value, editGoodsPrice) : Subtr(this.value, editGoodsPrice);
                        if(goodsPrice > 0) $('#'+this.id).val(goodsPrice);
                    });
                }
                layer.close(index);
            }
        });
    }
    //批量修改规格商品库存
    function editSpecGoodsStock() {
        let editHtml = '<div class="box-body">';
        editHtml += '<div class="col-sm-4" style="padding-right: 2px;"><select id="edit-spec-goods-stock-type" class="form-control input-sm"><option value="1">[<?php echo $this->translate('增加'); ?>]+</option><option value="2">[<?php echo $this->translate('减少'); ?>]-</option></select></div>';
        editHtml += '<div class="col-sm-5" style="padding-left: 2px;"><input type="number" min="0" id="edit-spec-goods-stock" value="0" class="form-control input-sm"></div>';
        editHtml += '</div>';
        layer.open({
            title: "<?php echo $this->translate('批量修改规格商品库存'); ?>",
            type: 1,
            skin: 'layui-layer-rim',
            area: ['400px', '180px'], //宽高
            content: editHtml,
            btn: '<?php echo $this->translate('点击修改'); ?>',
            yes: function(index){
                let editGoodsStock = $('#edit-spec-goods-stock').val();
                let editGoodsStockType = $('#edit-spec-goods-stock-type').val();
                let goodsStock = 0;
                if(editGoodsStock > 0) {
                    $("input[name='specGoodsStock[]']").each(function() {
                        goodsStock = editGoodsStockType == 1 ? accAdd(this.value, editGoodsStock) : Subtr(this.value, editGoodsStock);
                        if(goodsStock > 0) $('#'+this.id).val(goodsStock);
                    });
                }
                layer.close(index);
            }
        });
    }
    //批量修改规格商品货号
    function editSpecGoodsItem() {
        let editHtml = '<div class="box-body">';
        editHtml += '<div class="col-sm-8" style="padding-left: 2px;"><input type="text" id="edit-spec-goods-item" value="" class="form-control input-sm"></div>';
        editHtml += '</div>';
        layer.open({
            title: "<?php echo $this->translate('批量修改规格商品货号'); ?>",
            type: 1,
            skin: 'layui-layer-rim',
            area: ['400px', '180px'], //宽高
            content: editHtml,
            btn: '<?php echo $this->translate('点击修改'); ?>',
            yes: function(index){
                let editGoodsItem = $('#edit-spec-goods-item').val();
                let goodsItem = '';
                let goodsItemKey = 1;
                if(editGoodsItem.length > 0) {
                    $("input[name='specGoodsItem[]']").each(function() {
                        goodsItem = editGoodsItem+'-'+goodsItemKey;
                        $('#'+this.id).val(goodsItem);
                        goodsItemKey++;
                    });
                }
                layer.close(index);
            }
        });
    }
    //批量修改规格商品重量
    function editSpecGoodsWeight() {
        let editHtml = '<div class="box-body">';
        editHtml += '<div class="col-sm-4" style="padding-right: 2px;"><select id="edit-spec-goods-weight-type" class="form-control input-sm"><option value="1">[<?php echo $this->translate('增加'); ?>]+</option><option value="2">[<?php echo $this->translate('减少'); ?>]-</option></select></div>';
        editHtml += '<div class="col-sm-5" style="padding-left: 2px;"><input type="number" min="0" id="edit-spec-goods-weight" value="0" class="form-control input-sm"></div>';
        editHtml += '</div>';
        layer.open({
            title: "<?php echo $this->translate('批量修改规格商品重量'); ?>",
            type: 1,
            skin: 'layui-layer-rim',
            area: ['400px', '180px'], //宽高
            content: editHtml,
            btn: '<?php echo $this->translate('点击修改'); ?>',
            yes: function(index){
                let editGoodsWeight = $('#edit-spec-goods-weight').val();
                let editGoodsWeightType = $('#edit-spec-goods-weight-type').val();
                let goodsWeight = 0;
                if(editGoodsWeight > 0) {
                    $("input[name='specGoodsWeight[]']").each(function() {
                        goodsWeight = editGoodsWeightType == 1 ? accAdd(this.value, editGoodsWeight) : Subtr(this.value, editGoodsWeight);
                        if(goodsWeight > 0) $('#'+this.id).val(goodsWeight);
                    });
                }
                layer.close(index);
            }
        });
    }

    function getEditNewImage() {
        let imageIdStr = '';
        $("input[name='goodsImageId[]']").each(function() {
            if(this.value > 0) {
                imageIdStr += this.value + '|';
            }
        })

        $.post("<?php echo $this->url('goods', ['action'=> 'ajaxGetEditNewImage']); ?>",{goodsId:<?php echo isset($this->goodsInfo) ? $this->goodsInfo->getGoodsId() : '0'; ?>, imageIdStr:imageIdStr},
            function(data){
                if (data.state != 'false') {
                    let imageHtml = '';
                    for (let i = 0; i < data.imageList.length; i++) {
                        imageHtml += '<tr id="trImage'+data.imageList[i].goodsImageId+'">';
                        imageHtml += '<td><input type="hidden" name="goodsImageId[]" value="'+data.imageList[i].goodsImageId+'"><img src="'+(data.imageList[i].goodsThumbnailImage.indexOf("http") != -1 ? data.imageList[i].goodsThumbnailImage : basePath + data.imageList[i].goodsThumbnailImage)+'" class="img-thumbnail" style="width: 60px;height: 60px;"></td>';
                        imageHtml += '<td><input type="radio" name="defaultImage" value="'+data.imageList[i].goodsImageId+'"></td>';
                        imageHtml += '<td><input type="checkbox" name="imageSlide'+data.imageList[i].goodsImageId+'" id="imageSlide'+data.imageList[i].goodsImageId+'" value="1"></td>';
                        imageHtml += '<td><input type="number" min="1" name="imageSort'+data.imageList[i].goodsImageId+'" id="imageSort'+data.imageList[i].goodsImageId+'" value="255" class="form-control input-sm"></td>';
                        imageHtml += '<td>';
                        imageHtml += '<button type="button" class="btn btn-xs btn-success" onclick="updateGoodsImage('+data.imageList[i].goodsImageId+');"><i class="fa fa-refresh"></i> <?php echo $this->translate('更新'); ?></button>';
                        imageHtml += '<button type="button" class="btn btn-xs btn-danger" onclick="deleteGoodsImage('+data.imageList[i].goodsImageId+');" style="margin-left: 10px;"><i class="fa fa-trash"></i> <?php echo $this->translate('删除'); ?></button>';
                        imageHtml += '</td>';
                        imageHtml += '</tr>';
                    }
                    $('#goodsMoreImage').prepend(imageHtml);
                } else {
                    shopMessage('<?php echo $this->translate('无新的商品图片'); ?>');
                }
            }, 'json');
    }
</script>
